package com.xx.pmis.persistence.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;

import com.xx.pmis.model.Role;

/**
 * 
 */
public class RoleDAOImpl extends BaseHibernateDAOImpl<Role> implements RoleDAO {
	@SuppressWarnings("unchecked")
	public List<Role> getAllRole() {
		List<Role> roles;
		try {
			Query query = getSession().getNamedQuery("AllRoleQuery");
			roles = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return roles;
	}

	public Role getRoleByRoleID(String roleID) {
		Role role;
		try {
			role = (Role) getSession().get(Role.class, roleID);

		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return role;
	}
	
	public Role getRoleByRoleCode(String roleCode) {
		Role role;
		try {
			Query query = getSession().getNamedQuery("RoleByRoleCodeQuery");
			query.setString("roleCode", roleCode);
			role = (Role) query.uniqueResult();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return role;
	}

}
